package com.example.day09d_1;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import java.util.List;

public class Recy_Adapter extends RecyclerView.Adapter<Recy_Adapter.ViewHolder> {
    private List<GetBean.ResultsBean>beans;
    private Context context;

    public Recy_Adapter(List<GetBean.ResultsBean> beans, Context context) {
        this.beans = beans;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item, parent, false);

        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.t1.setText(beans.get(position).get_id()+"");
        Glide.with(context).load(beans.get(position).getUrl()).into(holder.img1);
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
      ImageView img1;
      TextView t1;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            img1=itemView.findViewById(R.id.img);
            t1=itemView.findViewById(R.id.text);
        }
    }

}
